/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.courier.view;

import com.sun.courier.dal.CityDAL;
import com.sun.courier.dal.CourierDAL;
import com.sun.courier.dal.CourierManageDAL;
import com.sun.courier.dal.DistrictDAL;
import com.sun.courier.entity.City;
import com.sun.courier.entity.Courier;
import com.sun.courier.entity.CourierManage;
import com.sun.courier.entity.District;
import com.sun.courier.utilities.Utilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author HONG QUAN
 */
public class ReceiveCourierFromCustomerActions extends JDialog implements ActionListener {

    CourierDAL courierDal = new CourierDAL();
    CourierManageDAL cmDal = new CourierManageDAL();

    JPanel pnMain = new JPanel();
    JPanel pnTitle = new JPanel();
    JPanel pnCenter = new JPanel();
    JPanel pnButton = new JPanel();

    JLabel lblTitle = new JLabel("Receive Courier From Customers");
    JLabel lblCourierId = new JLabel("Courier Id");
    JLabel lblReceiverName = new JLabel("Receiver Name");// Ten nhan vien nhan hang cua khach hang: lay tu dang nhap.
    JLabel lblCourierName = new JLabel("Courier Name");
    JLabel lblCustomerName = new JLabel("Customer Name");
    JLabel lblPhone = new JLabel("Phone");
    JLabel lblStatus = new JLabel("Status");
    JLabel lblWeight = new JLabel("Weight");
    JLabel lblDepartLocation = new JLabel("Sender Address");
    JLabel lblDestination = new JLabel("Receiver Address");
    JLabel lblDistance = new JLabel("Distance");
    JLabel lblUpdateTime = new JLabel("Update Time");
    JLabel lblDescription = new JLabel("Description");
    JLabel lblReceiver = new JLabel("Receiver Id");
    JLabel lblReceivingCus = new JLabel("Receiving Customer");
    
    JTextField txtCourierId = new JTextField();
    JTextField txtCourierName = new JTextField();
    JTextField txtReceiverName = new JTextField();
    JTextField txtCustomerName = new JTextField();
    JTextField txtPhone = new JTextField();
    JTextField txtStatus = new JTextField();
    JTextField txtWeight = new JTextField();
    JTextField txtDepartLocation = new JTextField();
    JTextField txtDestination = new JTextField();
    JTextField txtDistance = new JTextField();
    JTextField txtUpdateTime = new JTextField();
    JTextArea txtDescription = new JTextArea();
    JTextField txtReceiver = new JTextField();
    JTextField txtReceiving = new JTextField();
    
    JButton btnAdd = new JButton("Insert");
    JButton btnReset = new JButton("Reset");

    DefaultTableModel model = null;
    int row = -1;
    String empId = Utilities.empId;

    public ReceiveCourierFromCustomerActions(DefaultTableModel model, int row) {
        registerListeners();
        this.model = model;
        this.row = row;
        createControlPanel();
    }

    public void createControlPanel() {
        pnTitle.setLayout(new FlowLayout());
        pnTitle.setBorder(BorderFactory.createEtchedBorder());
        lblTitle.setFont(new Font("Arial", Font.BOLD, 25));
        pnTitle.add(lblTitle);

        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
        pnCenter.setBorder(BorderFactory.createEtchedBorder());
        pnCenter.setLayout(gridbag);

        c.gridx = 0;
        c.gridy = 0;
        c.gridheight = 1;
        c.insets = new Insets(5, 3, 3, 3);
        c.anchor = GridBagConstraints.SOUTHWEST;
        lblReceiverName.setVisible(false);
        pnCenter.add(lblReceiverName, c);

        c.gridx = 1;
        c.gridy = 0;
        c.gridheight = 1;
        c.insets = new Insets(5, 3, 0, 3);
        c.anchor = GridBagConstraints.SOUTHWEST;
        txtReceiverName.setVisible(false);
        txtReceiverName.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtReceiverName, c);

        c.gridx = 0;
        c.gridy = 1;
        c.gridheight = 1;
        c.insets = new Insets(5, 3, 3, 3);
        c.anchor = GridBagConstraints.SOUTHWEST;
        lblCourierId.setVisible(false);
        pnCenter.add(lblCourierId, c);

        c.gridx = 1;
        c.gridy = 1;
        c.gridheight = 1;
        c.insets = new Insets(5, 3, 0, 3);
        c.anchor = GridBagConstraints.SOUTHWEST;
        txtCourierId.setVisible(false);
        txtCourierId.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtCourierId, c);

        c.gridx = 0;
        c.gridy = 2;
        lblStatus.setVisible(false);
        pnCenter.add(lblStatus, c);

        c.gridx = 1;
        c.gridy = 2;
        txtStatus.setVisible(false);
        txtStatus.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtStatus, c);
        ///////////////////////////Phia tren la bi an di////////////////////
        c.gridx = 0;
        c.gridy = 1;
        pnCenter.add(lblCourierName, c);

        c.gridx = 1;
        c.gridy = 1;
        txtCourierName.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtCourierName, c);

        c.gridx = 0;
        c.gridy = 2;
        pnCenter.add(lblCustomerName, c);

        c.gridx = 1;
        c.gridy = 2;
        txtCustomerName.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtCustomerName, c);

        c.gridx = 0;
        c.gridy = 3;
        pnCenter.add(lblReceivingCus, c);

        c.gridx = 1;
        c.gridy = 3;
        txtReceiving.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtReceiving, c);
        
        c.gridx = 0;
        c.gridy = 4;
        pnCenter.add(lblPhone, c);

        c.gridx = 1;
        c.gridy = 4;
        txtPhone.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtPhone, c);

        c.gridx = 0;
        c.gridy = 6;
        pnCenter.add(lblWeight, c);

        c.gridx = 1;
        c.gridy = 6;
        txtWeight.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtWeight, c);

        c.gridx = 0;
        c.gridy = 7;
        pnCenter.add(lblDepartLocation, c);

        c.gridx = 1;
        c.gridy = 7;
        txtDepartLocation.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtDepartLocation, c);
        txtDepartLocation.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                PassAddressActions paa = new PassAddressActions();
                paa.setBackground(Color.GRAY);
                paa.setModal(true);
                paa.setAlwaysOnTop(true);
                paa.setSize(new Dimension(700, 300));
                paa.setVisible(true);
            }
        });

        c.gridx = 0;
        c.gridy = 8;
        pnCenter.add(lblDestination, c);

        c.gridx = 1;
        c.gridy = 8;
        txtDestination.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtDestination, c);
        txtDestination.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                PassAddressReceiverActions par = new PassAddressReceiverActions();
                par.setBackground(Color.GRAY);
                par.setModal(true);
                par.setAlwaysOnTop(true);
                par.setSize(new Dimension(650, 300));
                par.setVisible(true);
            }
        });

        c.gridx = 0;
        c.gridy = 9;
        pnCenter.add(lblDistance, c);

        c.gridx = 1;
        c.gridy = 9;
        txtDistance.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtDistance, c);

        c.gridx = 0;
        c.gridy = 10;
        lblUpdateTime.setVisible(false);
        pnCenter.add(lblUpdateTime, c);
        c.gridx = 1;
        c.gridy = 10;
        txtUpdateTime.setVisible(false);
        txtUpdateTime.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtUpdateTime, c);

        c.gridx = 0;
        c.gridy = 11;
        c.anchor = GridBagConstraints.BELOW_BASELINE_LEADING;
        pnCenter.add(lblDescription, c);
        c.gridx = 1;
        c.gridy = 11;
        txtDescription.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        txtDescription.setPreferredSize(new Dimension(300, 70));
        pnCenter.add(txtDescription, c);

        c.gridx = 0;
        c.gridy = 12;
        c.anchor = GridBagConstraints.BELOW_BASELINE_LEADING;
        lblReceiver.setVisible(false);
        pnCenter.add(lblReceiver, c);
        c.gridx = 1;
        c.gridy = 12;
        txtReceiver.setVisible(false);
        txtReceiver.setBorder(BorderFactory.createLineBorder(Color.GRAY));
        txtReceiver.setPreferredSize(new Dimension(300, 30));
        pnCenter.add(txtReceiver, c);

        pnButton.setLayout(new FlowLayout());
        pnButton.setBorder(BorderFactory.createEtchedBorder());
        pnButton.add(btnAdd);
        lblTitle.setText("Receive Courier From Customer");

        pnButton.add(btnReset);

        pnMain.setLayout(new BorderLayout());
        pnMain.setBackground(Color.LIGHT_GRAY);
        pnMain.setBorder(BorderFactory.createRaisedSoftBevelBorder());
        pnMain.add(pnTitle, BorderLayout.NORTH);
        pnMain.add(pnCenter, BorderLayout.CENTER);
        pnMain.add(pnButton, BorderLayout.SOUTH);

        getContentPane().add(pnMain, BorderLayout.CENTER);
    }

    public void setValuesOfCustomer(int receiverId) {
        txtReceiver.setText(Integer.toString(receiverId));
    }

    private void registerListeners() {
        btnAdd.addActionListener(this);
    }

    public void actionPerformed(ActionEvent ae) {
        try {
            if (ae.getSource().equals(btnAdd)) {
                if (txtCourierName.getText().isEmpty() || txtCourierName.getText().isEmpty()|| txtCustomerName.getText().isEmpty()
                        || txtCustomerName.getText().isEmpty() || txtDepartLocation.getText().isEmpty() || txtDepartLocation.getText().isEmpty()
                        || txtDestination.getText() == null || txtDestination.getText() == "" || txtDistance.getText() == null
                        || txtDistance.getText().isEmpty() || txtPhone.getText().isEmpty() || txtPhone.getText().isEmpty()
                        || txtWeight.getText().isEmpty()|| txtWeight.getText().isEmpty()) {
                    JOptionPane.showMessageDialog(pnCenter, "You can not left blank any textboxes!", "Result", JOptionPane.INFORMATION_MESSAGE);
                    return;
                } else {
                    addNewCourier();
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    private void addNewCourier() {
        Courier c = new Courier();
        c.setCourierName(txtCourierName.getText());
        c.setCustomerName(txtCustomerName.getText());
        c.setReceivingCustomer(txtReceiving.getText());
        c.setPhone(txtPhone.getText());
        c.setStatus("Received Courier From Customers");
        c.setWeight(txtWeight.getText());
        c.setDepartLocation(txtDepartLocation.getText());
        c.setDestination(txtDestination.getText());
        c.setDistance(txtDistance.getText());
        Boolean rs = courierDal.insertCourier(c);
        Object[][] data = null;
        if (rs) {
            Boolean kq = insertIntoCourierManage();
            if (kq) {
                JOptionPane.showMessageDialog(pnCenter, "Insert Successful!", "Result", JOptionPane.INFORMATION_MESSAGE);
                data = new Object[1][7];
                data[0][0] = txtCourierId.getText();
                data[0][1] = txtCourierName.getText();
                data[0][2] = txtCustomerName.getText();
                data[0][3] = txtPhone.getText();
                data[0][4] = courierDal.getEmployeeName(Integer.parseInt(empId));                       //txtReceiver.getText();
                data[0][5] = "Received";
                data[0][6] = txtUpdateTime.getText();
                model.addRow(data[0]);
                model.fireTableDataChanged();
                this.dispose();
            }
        } else {
            JOptionPane.showMessageDialog(pnCenter, "Insert Fail!", "Result", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
    }

    protected Boolean insertIntoCourierManage() {
        Date dNow = new Date();
        SimpleDateFormat ft = new SimpleDateFormat("MM/dd/yyyy");
        CourierManage c = new CourierManage();
        txtCourierId.setText(Integer.toString(getLastCourierId()));
        c.setCourierId(Integer.parseInt(txtCourierId.getText()));
        c.setReceiver(Integer.parseInt(txtReceiver.getText()));//Cai nay tam set la 2: Integer.parseInt(txtReceiverName.getText())
        c.setDescription(txtDescription.getText());
        txtUpdateTime.setText(ft.format(dNow));
        c.setUpdatetime(ft.format(dNow));
        Boolean rs = cmDal.insertIntoCourierManage(c);
        return rs;
    }

    protected int getLastCourierId() {
        int lastId = courierDal.getLastId().get(0).getCourierId();
        return lastId;
    }

    //INNER CLASS
    private class PassAddressActions extends JDialog implements ActionListener {

        GridBagLayout gridbagInner = new GridBagLayout();
        GridBagConstraints cInner = new GridBagConstraints();

        JPanel lblTitleInner = new JPanel();
        JPanel pnMainInner = new JPanel();
        JPanel pnTitleInner = new JPanel();
        JPanel pnCenterInner = new JPanel();
        JPanel pnButtomInner = new JPanel();

        JLabel lblAddress = new JLabel("Address");
        JLabel lblCity = new JLabel();
        JLabel lblDistrict = new JLabel();

        JTextField txtAddress = new JTextField();
        JComboBox cbCity;
        JComboBox cbDistrict = new JComboBox();
        JButton btnOK = new JButton("OK");

        ArrayList<City> lstCity = new ArrayList<>();
        ArrayList<District> lstDis = new ArrayList<>();
        CityDAL cDal = new CityDAL();
        DistrictDAL dDal = new DistrictDAL();

        ReceiveCourierFromCustomerActions rca;
        Vector modelCity;

        public PassAddressActions() {
            lstCity = cDal.getAllCity();
            lstDis = dDal.getAllDistrict();
            createInnerControlPanel();
            registerActionListener();
        }

        public void createInnerControlPanel() {
            modelCity = showAllCityToCombo();
            lblTitleInner.setFont(new Font("Arial", Font.BOLD, 25));
            pnTitleInner.add(lblTitleInner);
            
            pnCenterInner.setBorder(BorderFactory.createEtchedBorder());
            pnCenterInner.setLayout(gridbagInner);

            cInner.gridx = 0;
            cInner.gridy = 0;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 3, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            pnCenterInner.add(lblAddress, cInner);

            cInner.gridx = 1;
            cInner.gridy = 0;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 0, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            txtAddress.setPreferredSize(new Dimension(300, 30));
            pnCenterInner.add(txtAddress, cInner);

            cInner.gridx = 0;
            cInner.gridy = 1;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 3, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            pnCenterInner.add(lblCity, cInner);

            cInner.gridx = 1;
            cInner.gridy = 1;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 0, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            cbCity = new JComboBox(modelCity);
            cbCity.setPreferredSize(new Dimension(300, 30));
            pnCenterInner.add(cbCity, cInner);

            cInner.gridx = 0;
            cInner.gridy = 2;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 3, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            pnCenterInner.add(lblDistrict, cInner);

            cInner.gridx = 1;
            cInner.gridy = 2;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 0, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            cbDistrict.setPreferredSize(new Dimension(300, 30));
            pnCenterInner.add(cbDistrict, cInner);

            pnButtomInner.add(btnOK);

            pnMainInner.setLayout(new BorderLayout());
            pnMainInner.setBackground(Color.LIGHT_GRAY);
            pnMainInner.setBorder(BorderFactory.createRaisedSoftBevelBorder());
            pnMainInner.add(pnTitleInner, BorderLayout.NORTH);
            pnMainInner.add(pnCenterInner, BorderLayout.CENTER);
            pnMainInner.add(pnButtomInner, BorderLayout.SOUTH);

            getContentPane().add(pnMainInner, BorderLayout.CENTER);
        }

        private Vector showAllCityToCombo() {
            Vector modelct = new Vector();
            modelct.add(0, "Choose A City");
            for (int i = 0; i < lstCity.size(); i++) {
                modelct.addElement(new Item(lstCity.get(i).getCityId(), lstCity.get(i).getCityName().toString()));
            }
            return modelct;
        }

        private void registerActionListener() {
            btnOK.addActionListener(this);
            cbCity.addActionListener(this);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource().equals(btnOK)) {

                String add = txtAddress.getText() + " - " + cbDistrict.getSelectedItem() + " - " + cbCity.getSelectedItem();
                txtDepartLocation.setText(add);
                this.dispose();
            } else if (e.getSource().equals(cbCity)) {
                getDistrictCorresponding();
            }
        }

        private void getDistrictCorresponding() {
            Item item = (Item) cbCity.getSelectedItem();
            int ctId = item.getId();
            cbDistrict.removeAllItems();
            cbDistrict.addItem("Choose A District");
            for (int i = 0; i < lstDis.size(); i++) {
                if (lstDis.get(i).getCityId() == ctId) {
                    cbDistrict.addItem(lstDis.get(i).getDistrictName().toString());
                }
            }
        }
    }
    //INNER RECEIVER CLASS

    private class PassAddressReceiverActions extends JDialog implements ActionListener {

        GridBagLayout gridbagInner = new GridBagLayout();
        GridBagConstraints cInner = new GridBagConstraints();

        JPanel pnMainInner = new JPanel();
        JPanel pnTitleInner = new JPanel();
        JPanel pnCenterInner = new JPanel();
        JPanel pnButtomInner = new JPanel();

        JLabel lblTitleInner = new JLabel("Select Your City and District");
        JLabel lblAddress = new JLabel("Address");
        JLabel lblCity = new JLabel();
        JLabel lblDistrict = new JLabel();

        JTextField txtAddress = new JTextField();
        JComboBox cbCity;
        JComboBox cbDistrict = new JComboBox();
        JButton btnOK = new JButton("OK");

        ArrayList<City> lstCity = new ArrayList<>();
        ArrayList<District> lstDis = new ArrayList<>();
        CityDAL cDal = new CityDAL();
        DistrictDAL dDal = new DistrictDAL();

        ReceiveCourierFromCustomerActions rca;
        Vector modelCity;

        public PassAddressReceiverActions() {
            lstCity = cDal.getAllCity();
            lstDis = dDal.getAllDistrict();
            createInnerControlPanel();
            registerActionListener();
        }

        public void createInnerControlPanel() {
            modelCity = showAllCityToCombo();
            lblTitleInner.setFont(new Font("Arial", Font.BOLD, 25));
            pnTitleInner.add(lblTitleInner);
            
            pnCenterInner.setBorder(BorderFactory.createEtchedBorder());
            pnCenterInner.setLayout(gridbagInner);

            cInner.gridx = 0;
            cInner.gridy = 0;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 3, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            pnCenterInner.add(lblAddress, cInner);

            cInner.gridx = 1;
            cInner.gridy = 0;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 0, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            txtAddress.setPreferredSize(new Dimension(300, 30));
            pnCenterInner.add(txtAddress, cInner);

            cInner.gridx = 0;
            cInner.gridy = 1;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 3, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            pnCenterInner.add(lblCity, cInner);

            cInner.gridx = 1;
            cInner.gridy = 1;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 0, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            cbCity = new JComboBox(modelCity);
            cbCity.setPreferredSize(new Dimension(300, 30));
            pnCenterInner.add(cbCity, cInner);

            cInner.gridx = 0;
            cInner.gridy = 2;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 3, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            pnCenterInner.add(lblDistrict, cInner);

            cInner.gridx = 1;
            cInner.gridy = 2;
            cInner.gridheight = 1;
            cInner.insets = new Insets(5, 3, 0, 3);
            cInner.anchor = GridBagConstraints.SOUTHWEST;
            cbDistrict.setPreferredSize(new Dimension(300, 30));
            pnCenterInner.add(cbDistrict, cInner);

            pnButtomInner.add(btnOK);

            pnMainInner.setLayout(new BorderLayout());
            pnMainInner.setBackground(Color.LIGHT_GRAY);
            pnMainInner.setBorder(BorderFactory.createRaisedSoftBevelBorder());
            pnMainInner.add(pnTitleInner, BorderLayout.NORTH);
            pnMainInner.add(pnCenterInner, BorderLayout.CENTER);
            pnMainInner.add(pnButtomInner, BorderLayout.SOUTH);

            getContentPane().add(pnMainInner, BorderLayout.CENTER);
        }

        private Vector showAllCityToCombo() {
            Vector modelct = new Vector();
            modelct.add(0, "Choose A City");
            for (int i = 0; i < lstCity.size(); i++) {
                modelct.addElement(new Item(lstCity.get(i).getCityId(), lstCity.get(i).getCityName().toString()));
            }
            return modelct;
        }

        private void registerActionListener() {
            btnOK.addActionListener(this);
            cbCity.addActionListener(this);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource().equals(btnOK)) {

                String add = txtAddress.getText() + " - " + cbDistrict.getSelectedItem() + " - " + cbCity.getSelectedItem();
                txtDestination.setText(add);
                this.dispose();
            } else if (e.getSource().equals(cbCity)) {
                getDistrictCorresponding();
            }
        }

        private void getDistrictCorresponding() {
            Item item = (Item) cbCity.getSelectedItem();
            int ctId = item.getId();
            cbDistrict.removeAllItems();
            cbDistrict.addItem("Choose A District");
            for (int i = 0; i < lstDis.size(); i++) {
                if (lstDis.get(i).getCityId() == ctId) {
                    cbDistrict.addItem(lstDis.get(i).getDistrictName().toString());
                }
            }
        }
    }

    //INNER IN INNER CLASS
    class ItemRenderer extends BasicComboBoxRenderer {

        public Component getListCellRendererComponent(
                JList list, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index,
                    isSelected, cellHasFocus);

            if (value != null) {
                Item item = (Item) value;
                setText(item.getDescription().toUpperCase());
            }

            if (index == -1) {
                Item item = (Item) value;
                setText("" + item.getId());
            }

            return this;
        }
    }

    class Item {

        private int id;
        private String description;

        public Item(int id, String description) {
            this.id = id;
            this.description = description;
        }

        public int getId() {
            return id;
        }

        public String getDescription() {
            return description;
        }

        public String toString() {
            return description;
        }
    }
        //INNER IN INNER CLASS
}
